package cn.com.weather.nf.service;

import cn.com.weather.nf.repository.Cctest1Dao;
import cn.com.weather.nf.entity.Cctest1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Service
public class RunTestService {

    private static final Logger LOGGER = LoggerFactory.getLogger(RunTestService.class);

    @Autowired
    private JdbcTemplate jdbcTemplate;

//    @Autowired
    private Cctest1Dao cctest1Dao;

    public List<String> getData() {

        String sql = "SELECT * FROM `sun_record_weather`";
        LOGGER.info("dataSource : {}", this.jdbcTemplate.getDataSource().getClass().getSimpleName());
        return jdbcTemplate.query(sql, new RowMapper<String>(){

            @Override
            public String mapRow(ResultSet resultSet, int i) throws SQLException {
                return resultSet.getString("addr_info");
            }
        });
    }

    public List<Cctest1> getList() {
        return this.cctest1Dao.getList();
    }

    public List<Cctest1> findById(Integer id) {
        return this.cctest1Dao.findById(id);
    }
}
